﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Film.Common
{
    public class UtilString
    {
        /// <summary>
        /// Dùng để tìm kiếm không dấu
        /// Ví dụ:  keyWord = Util.XacDinhNguyenAm(keyWord.Trim())
        /// result = (from ds in dataContext.Products where ds.Active && (System.Data.Linq.SqlClient.SqlMethods.Like(ds.Name, "%" + keyWord + "%")  || System.Data.Linq.SqlClient.SqlMethods.Like(ds.Code, "%" + keyWord + "%")) orderby ds.LastUpdate descending select ds).ToList()
        /// </summary>
        /// <param name="searchKey"></param>
        /// <returns></returns>
        public static string XacDinhNguyenAm(string searchKey)
        {
            searchKey = searchKey.ToLower();
            char[] charArr = searchKey.ToCharArray();
            searchKey = "";
            foreach (char c in charArr)
            {
                string tmp = "";
                tmp = c.ToString();

                if (c == 'a')
                {
                    tmp = "[aáàạảãâấầậẩẫăắằặẳẵ]";
                }
                if (c == 'e')
                {
                    tmp = "[eéèẹẻẽêếềệểễ]";
                }
                if (c == 'o')
                {
                    tmp = "[oóòọỏõôốồộổỗơớờợởỡ]";
                }
                if (c == 'i')
                {
                    tmp = "[iíìịỉĩ]";
                }
                if (c == 'u')
                {
                    tmp = "[uúùụủũưứừựửữ]";
                }
                if (c == 'd')
                {
                    tmp = "[dđ]";
                }
                if (c == 'y')
                {
                    tmp = "[ýyỳỷỹ]";
                }
                searchKey += tmp;
            }
            return searchKey;
        }
    }
}
